﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;

namespace MT.CustomUserControl.ViewModels
{
    public class SimpleSearchUcViewModel:ObservableObject
    {
        /// <summary>
        /// The search information
        /// </summary>
        private string searchInfo = string.Empty;
        public string SearchInfo
        {
            get { return searchInfo; }
            set { SetProperty(ref searchInfo, value); }
        }

        /// <summary>
        /// 删除搜索内容的命令
        /// </summary>
        private RelayCommand deleteSearchInfoCommond;
        public RelayCommand DeleteSearchInfoCommond
        {
            get
            {
                if (deleteSearchInfoCommond == null)
                {
                    deleteSearchInfoCommond = new RelayCommand(DeleteSearchInfoCommondFunc);
                }
                return deleteSearchInfoCommond;
            }
        }

        /// <summary>
        /// The search commond
        /// </summary>
        private RelayCommand searchCommond;
        public RelayCommand SearchCommond
        {
            get
            {
                if (searchCommond == null)
                {
                    searchCommond = new RelayCommand(SearchCommondFunc);
                }
                return searchCommond;
            }
        }

        public Action DeleteSearchAction;
        public Action<string> SearchAction;

        public SimpleSearchUcViewModel()
        {
            
        }

        /// <summary>
        /// 删除搜索内容的命令
        /// </summary>
        public void DeleteSearchInfoCommondFunc()
        {
            SearchInfo = string.Empty;
            DeleteSearchAction?.Invoke();
        }

        /// <summary>
        /// Searches the commond function.
        /// </summary>
        public void SearchCommondFunc()
        {
            SearchAction?.Invoke(SearchInfo);
        }
    }
}
